Ext.define('Admin.view.processmodel.ProcessModelViewController', {
    extend: Ext.app.ViewController,
    alias: 'controller.processmodel',
    onClickProcessModelGridAddButton: function(btn) {
		Ext.create(Ext.apply({xtype: 'processmodel-create-window'}));
    },
   
    onClickProcessModelCreateFormCancelButton: function (btn) {
		var win = btn.up('window');
        if (win) {
            win.close();
        }
    },
	onClickProcessModelCreateFormSubmitButton: function (btn) {
		var form = btn.up('form');
		form.getForm().submit({       
			url:'model/create',
			success: function(form, action){
				
				Ext.Msg.alert('系统提示', "创建成功!",function(){
					btn.up('window').close();
                    Ext.getCmp('processmodel-grid').getStore().reload();
                    window.open(action.result.msg);
				});       
			},       
			failure: function(form, action){
				Ext.Msg.alert('系统提示', action.result.msg);
			}
		});
    },
    onClickProcessModelGridDeployButton: function(view, recIndex, cellIndex, item, e, record) {
        Ext.Ajax.request({ 
			url : 'model/deploy/'+record.get('id'), 
			method : 'post', 
			success: function(response, options) {
                var json = Ext.util.JSON.decode(response.responseText);
	            if(json.success){
	            	Ext.Msg.alert('系统提示', json.msg, function() {
	                    view.getStore().reload();
	                });
		        }else{
		        	 Ext.Msg.alert('系统提示', json.msg);
		        }
            }
		});
    },
    onClickProcessModelGridDeleteButton: function(view, recIndex, cellIndex, item, e, record) {
        Ext.Ajax.request({ 
			url : 'model/delete/'+record.get('id'), 
			method : 'post', 
			success: function(response, options) {
                var json = Ext.util.JSON.decode(response.responseText);
	            if(json.success){
	            	Ext.Msg.alert('系统提示', json.msg, function() {
	                    view.getStore().reload();
	                });
		        }else{
		        	 Ext.Msg.alert('系统提示', json.msg);
		        }
            }
		});
    }
});